Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-portal

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-portal

React component for transportation of modals, lightboxes, loading bars... to document.body

  • 3.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
588K
decreased by-7.21%
Maintainers
1
Weekly downloads
 
Created

What is react-portal?

The react-portal package allows you to render components into a DOM node that exists outside the DOM hierarchy of the parent component. This is useful for creating modals, tooltips, and other UI elements that need to be rendered outside the main document flow.

What are react-portal's main functionalities?

Basic Portal Usage

This example demonstrates the basic usage of the react-portal package. It renders a div element outside the main DOM hierarchy, which can be useful for creating modals or tooltips.

import React from 'react';
import ReactDOM from 'react-dom';
import { Portal } from 'react-portal';

function App() {
  return (
    <div>
      <h1>Main App</h1>
      <Portal>
        <div style={{ position: 'absolute', top: '50px', left: '50px', background: 'white', border: '1px solid black', padding: '10px' }}>
          This is a portal content
        </div>
      </Portal>
    </div>
  );
}

export default App;

Custom Portal Target

This example shows how to use a custom DOM node as the target for the portal. The content will be rendered inside the specified custom target element.

import React, { useRef } from 'react';
import ReactDOM from 'react-dom';
import { Portal } from 'react-portal';

function App() {
  const customTarget = useRef(null);

  return (
    <div>
      <h1>Main App</h1>
      <div ref={customTarget} id="custom-target" style={{ position: 'relative', height: '200px', border: '1px solid black' }}>
        Custom Target
      </div>
      <Portal node={customTarget.current}>
        <div style={{ position: 'absolute', top: '10px', left: '10px', background: 'white', border: '1px solid black', padding: '10px' }}>
          This is a portal content inside custom target
        </div>
      </Portal>
    </div>
  );
}

export default App;

Other packages similar to react-portal

Keywords

FAQs

Package last updated on 19 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc